<?php
            $this->headTitle($this->title);
             $this->headScript()->appendFile(Zend_Registry::get('static_path').'js/users.js');
            $this->headLink()->appendStylesheet(Zend_Registry::get('static_path').'css/user.css');
            $this->layout()->setLayout('userlayout');
?>
<div class="nav"><a href="<?php echo $this->url(array( 'controller' => 'admin', 'action'     => 'index'),'default', true) ?>" class="navlink">Control Panel</a><img src="../images/arrow.gif" class="arrow"/> Edit User</div>
<div id="userForm">
    <ul class="tabs">
        <li><a href="<?php echo $this->url(array( 'controller' => 'user', 'action'     => 'add'),'default', true) ?>">Add User</a></li>
        <li class="active"><a href="<?php echo $this->url(array( 'controller' => 'user', 'action'     => 'edit'),'default', true) ?>">Edit User</a></li>
    </ul>
    <div id="form-container">
        <form name="search"  class="form" id="search" method="post" action="<?php echo $this->url(array( 'controller' => 'user', 'action'     => 'edit'),'default', true) ?>">
                <fieldset class="form">
                        <legend>Search a User:</legend>
                        <label>First Name:</label> <input type="text" name="_firstName" value="<?php echo $this->firstName ?>"/>
                        <label>Last Name:</label> <input type="text" name="_lastName" value="<?php echo $this->lastName ?>"/>
                        <label>Address:</label> <input type="text" name="_address1" value="<?php echo $this->address1?>"/>
                        <input type="submit" value="Search"/>   
                         <input type="hidden" name="action" value="_search"/>
                </fieldset>
        </form>
             <?php
                          if($this->data !=null){?>
                              <form name="editForm" id="editForm"   class="form" action="<?php echo $this->url(array( 'controller' => 'user', 'action'     => 'edit'),'default', true) ?>" method="post">
                               <table class="dataTable">
                                   <tbody>
                                       <tr>
                                           <td colspan="2" align="center"><div id="message"><?php echo $this->message?></div></td>
                                       </tr>
                                       <tr>
                                           <td width="20%">
                                               <label>Email Address:</label>
                                           </td>
                                            <td>
                                                <b><?php echo $this->data->getEmailAddress() ?></b>
                                            </td>
                                       </tr>
                                       <tr>
                                           <td width="20%">
                                               <label>First Name:<img src="../images/redStar.gif"/></label>
                                           </td>
                                            <td>
                                                <input type="text" name="firstName"  id="firstName"  value="<?php echo $this->data->getFirstName()?>"  size="30" maxlength="30">
                                            </td>
                                       </tr>
                                        <tr>
                                            <td width="20%">
                                                <label>Last Name:<img src="../images/redStar.gif"/></label>
                                            </td>
                                            <td>
                                                <input type="text" name="lastName"  id="lastName" value="<?php echo $this->data->getLastName()?>"  size="30" maxlength="30">
                                            </td>
                                        </tr>
                                        <tr>
                                            <td width="20%">
                                                <label>Address Line 1:</label>
                                            </td>
                                             <td>
                                                 <input type="text" name="address1"  size="50" value="<?php echo $this->data->getAddress1()?>" maxlength="50">
                                             </td>
                                        </tr>
                                        <tr>
                                            <td width="20%">
                                                <label>Address Line 2:</label>
                                            </td>
                                            <td>
                                                <input type="text" name="address2" size="50" value="<?php echo $this->data->getAddress2()?>"  maxlength="50">
                                            </td>
                                        </tr>
                                        <tr>
                                            <td width="20%">
                                                <label>City:</label>
                                            </td>
                                            <td>
                                                <input type="text" name="city" maxlength="20" value="<?php echo $this->data->getCity()?>" >
                                            </td>
                                        </tr>
                                        <tr>
                                            <td width="20%">
                                                <label>State:</label>
                                            </td>
                                            <td>
                                                <select id="state" name="state" ></select>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td width="20%">
                                                <label>Country:</label>
                                            </td>
                                             <td>
                                                 <select id="country" name="country" ></select>
                                             </td>
                                          </tr>
                                          <tr>
                                              <td width="20%">
                                                  <label>Zip:</label>
                                              </td>
                                              <td>
                                                  <input type="text" name="zip" maxlength="5" size="6" value="<?php echo $this->data->getZip()?>">
                                              </td>
                                        </tr>
                                        <tr>
                                            <td width="20%">
                                                <label>Phone Number 1:</label>
                                            </td>
                                            <td>
                                                <input type="text" name="phone1" maxlength="20" value="<?php echo $this->data->getPhone1()?>"  size="11">
                                            </td>
                                        </tr>
                                        <tr>
                                            <td width="20%">
                                                <label>Phone Number 2:</label>
                                            </td>
                                            <td>
                                                <input type="text" name="phone2" maxlength="20" size="11" value="<?php echo $this->data->getPhone2()?>">
                                            </td>
                                        </tr>
                                        <tr>
                                            <td width="20%">
                                                <label>Cell:</label>
                                            </td>
                                            <td>
                                                <input type="text" name="cell" maxlength="20" size="11" value="<?php echo $this->data->getCell()?>">
                                            </td>
                                        </tr>
                                        <tr>
                                            <td width="20%">
                                                <label>Email 2:</label>
                                            </td>
                                            <td>
                                                <input type="text" name="email2"  size="30" maxlength="30" value="<?php echo $this->data->getEmail2()?>">
                                            </td>
                                        </tr>
                                        <tr>
                                            <td width="20%">
                                                <label>Privileges:<img src="../images/redStar.gif"/></label></td>
                                            <td>
                                                 <input type="checkbox" name="option1" id="option1" value="Y"     <?php if($this->data->getResident() =="Y"){ echo   "checked";}?>> Resident&nbsp;&nbsp;
                                                 <input type="checkbox" name="option2"   id="option2" value="Y"   <?php if($this->data->getAdmin() =="Y"){ echo   "checked";}?>> Admin &nbsp;&nbsp;&nbsp;<span id="roleError"></span>
                                             </td>
                                        </tr>
                                            <tr>
                                                <td width="20%">
                                                    <label>Active:</label>
                                                </td>
                                                <td>
                                                        <input type="checkbox" name="active" id="active" value="Y" <?php if($this->data->getActiveFlag() =="Y"){ echo   "checked";}?>>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td colspan="2" align="center">
                                                    <input type="button" id="editUser" value="Submit"/>&nbsp;&nbsp;<input type="button" id="cancel"  value="Cancel"/>
                                                </td>
                                            </tr>
                                   </tbody>
                               </table>
                                <input type="hidden" id="_country" value="<?php echo $this->data->getCountry()?>"/>
                                <input type="hidden" id="_state" value="<?php echo $this->data->getState()?>"/>
                                <input type="hidden" id="userId" name="userId" value="<?php echo $this->data->getUserId()?>"/>
                                <input type="hidden" id="emailAddress"   name="emailAddress" value="<?php echo $this->data->getEmailAddress()?>"/>
                                <input type="hidden" name="_firstName" value="<?php echo $this->firstName ?>"/>
                                <input type="hidden" name="_lastName" value="<?php echo $this->lastName ?>"/>
                                <input type="hidden" name="_address1" value="<?php echo $this->address1 ?>"/>
                                <input type="hidden" name="action" value="_save"/>
                           </form>
                         <?php     }  ?>
        <?php    if($this->result !=null){     ?>
              <div id="searchData">
<!--                                <div align="right">
                                      <?php if (sizeof($this->result) >0){ ?>
                                          <a href="javascript:;" id="print">PDF</a>
                                      <?php } ?>
                                      </div>-->
                         <table class='searchresult'>
                              <thead>
                                  <tr>
                                      <td><a href="javascript:;" class="headerlink" id="FIRST_NAME" title="Click here to sort">First Name</a><span id="FIRST_NAME_SORT"></span></td>
                                      <td><a href="javascript:;" class="headerlink" id="LAST_NAME" title="Click here to sort">Last Name</a><span id="LAST_NAME_SORT"></span></td>
                                      <td><a href="javascript:;" class="headerlink" id="ADDRESS_LINE_1" title="Click here to sort">Address</a><span id="ADDRESS_LINE_1_SORT"></span></td>
                                      <td><a href="javascript:;" class="headerlink" id="ACTIVE_FLAG" title="Click here to sort">Active</a><span id="ACTIVE_FLAG_SORT"></span></td>
                                  </tr>
                              </thead>
                              <tbody>
                                     <?php foreach ($this->result as $data){ ?>
                                      <tr id='<?php echo $data->USER_ID ?>'>
                                            <td><?php echo  $data->FIRST_NAME ?></td>
                                            <td><?php echo  $data->LAST_NAME ?></td>
                                            <td><?php echo  $data->ADDRESS_LINE_1 ?></td>
                                             <td><?php echo  $data->ACTIVE_FLAG ?></td>
                                      </tr>
                                    <?php  }
                                          if (sizeof($this->result) ==0){ ?>
                                      <tr>
                                          <td colspan ="4">
                                              <font color="red">No Records found. </font>
                                          </td>
                                      </tr>
                               <?php      }
                                    ?>
                              </tbody>
                          </table>
           </div>
        <form name="mainForm" id="mainForm" action="<?php echo $this->url(array( 'controller' => 'user', 'action'     => 'edit'),'default', true) ?>" method="post">
                    <input type="hidden" name="_firstName" value="<?php echo $this->firstName ?>"/>
                    <input type="hidden" name="_lastName" value="<?php echo $this->lastName ?>"/>
                    <input type="hidden" name="_address1" value="<?php echo $this->address1 ?>"/>
                    <input type="hidden" name="_sortBy" id="_sortBy" value="<?php echo $this->sortBy ?>"/>
                    <input type="hidden" name="action" id="action" value=""/>
                    <input type="hidden" name="userId" id="userId" value=""/>
        </form>
   <?php } ?>
   </div>
</div>
<script>
 $(document).ready(function(){
      $.getJSON("../process/country", function(call){
         var selected="";
         $.each(call, function(key, value){
             if(key==$("#_country").val()){selected = "selected"}else{selected =""};
          $("#country").append('<option value="'+key+'" '+selected+'>'+value+'</option>');
        });
     });

   $.getJSON("../process/state", function(call){
         var selected="";
         $.each(call, function(key, value){
             if(key==$("#_state").val()){selected = "selected"}else{selected =""};
          $("#state").append('<option value="'+key+'" '+selected+'>'+value+'</option>');
        });
     });

     $("#cancel").click(function(){
            window.location="<?php echo $this->url(array( 'controller' => 'user', 'action'     => 'edit'),'default', true) ?>";
     });

       if($("form#mainForm>input#_sortBy").val() !=""){
                var arr =$("form#mainForm>input#_sortBy").val().split(' ');
                var img="";
                if(arr[1]=="ASC"){
                    img="<img src='../images/asc.gif'/>";
                }else  if(arr[1]=="DESC"){
                     img="<img src='../images/desc.gif'/>";
                }
                $("#"+arr[0]+"_SORT").html(img);
            }

        $("#print").click(function(){
            $("form#mainForm>input#action").val("_print");
            $("form#mainForm").submit();
     });

 });
 </script>


